#include ".\mygamecheckbox.h"

CMyGameCheckBox::CMyGameCheckBox(void)
{
	m_cbsState = CBS_Unchecked;
	m_strText = "A CheckBox";
}

CMyGameCheckBox::~CMyGameCheckBox(void)
{
}

void CMyGameCheckBox::Update()
{
	if (m_cbsState == CBS_Disable)
	{
		return;
	}
	if (m_pChildWndLock == NULL)
	{
		if (m_cbsState != CBS_Checked)
		{
			m_cbsState = CBS_Unchecked;
		}
	}
	return;
}

void CMyGameCheckBox::Draw(HDC hDC)
{
	CMyGameWindow::Draw(hDC);
	int nSrcX = m_cbsState * m_sprCheckBoxBmp.GetWidth() / 4;
	int nSrcY = 0;
	int nSrcWidth = m_sprCheckBoxBmp.GetWidth() / 4;
	int nSrcHeight = m_sprCheckBoxBmp.GetHeight();
	m_sprCheckBoxBmp.DrawRect(hDC,m_ptScreenPos.x,m_ptScreenPos.y,nSrcX,nSrcY,nSrcWidth,nSrcHeight);
	COLORREF crOldColor = GetTextColor(hDC);
	SetTextColor(hDC,m_crTextColor);
	TextOut(hDC,m_ptScreenPos.x + nSrcWidth + 2,m_ptScreenPos.y + 2,m_strText.c_str(),m_strText.length());
	SetTextColor(hDC,crOldColor);

}

void CMyGameCheckBox::LoadRes(LPCSTR szFileName)
{
	m_sprCheckBoxBmp.Load(NULL,szFileName);
}

void CMyGameCheckBox::SetEnable(BOOL bEnable)
{
	return;
}

BOOL CMyGameCheckBox::IsChecked()
{
	return m_cbsState == CBS_Checked;
}

BOOL CMyGameCheckBox::LBtnDown(int x,int y)
{
	if (m_cbsState == CBS_Disable)
	{
		return TRUE;
	}
	m_pChildWndLock = this;
	if (m_cbsState == CBS_Unchecked)
	{
		m_cbsState = CBS_MouseDown;
	}
	return TRUE;
}

BOOL CMyGameCheckBox::LBtnUp(int x,int y)
{
	if (m_pChildWndLock == this)
	{
		if (m_cbsState == CBS_MouseDown)
		{
			m_cbsState = CBS_Checked;
		}
		else if (m_cbsState == CBS_Checked)
		{
			m_cbsState = CBS_Unchecked;
		}
	}
	return TRUE;
}

BOOL CMyGameCheckBox::MouseMove(int x,int y)
{
	return TRUE;
}
